//
//  NSDictionary+SafeMethod.swift
//  FearfulNotification
//
//  Created by 筱鹏 on 2017/8/24.
//  Copyright © 2017年 筱鹏. All rights reserved.
//

import Foundation

extension NSDictionary {
    
    func obj(withKey:String) -> AnyObject? {
        let value = self.object(forKey: withKey) as AnyObject?
        if value == nil || (value?.isKind(of: NSNull.self))! {
            return nil
        } else {
            return value as AnyObject?
        }
    }
    
    func string(withKey:String) -> String {
        let value = self.object(forKey: withKey) as AnyObject?
        if value == nil || (value?.isKind(of: NSNull.self))! {
            return ""
        } else {
            guard let tmpStr = value else { return "" }
            return tmpStr as! String
        }
    }
    
    func int(withKey:String) -> Int {
        let value = self.object(forKey: withKey) as AnyObject?
        if value == nil || (value?.isKind(of: NSNull.self))! {
            return 0
        } else {
            guard let tmpStr = value else { return 0 }
            return tmpStr as! Int
        }
    }
}
